﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Catering_DBOpertion;
using System.Data;

namespace Catering_Operation
{
    public partial class ContractorDailyMangement
    {
        public ContractorDailyMangement() { }

        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ContractorDailyMangement");
            strSql.Append(" where CDID=@CDID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CDID", SqlDbType.Int,4)};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Catering_Model.ContractorDailyMangement model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ContractorDailyMangement(");
            strSql.Append("CID,ClassID,GroupID,ContentDesc,DTime)");
            strSql.Append(" values (");
            strSql.Append("@CID,@ClassID,@GroupID,@ContentDesc,@DTime)");
            SqlParameter[] parameters = {
					new SqlParameter("@CID", SqlDbType.Int,4),
					new SqlParameter("@ClassID", SqlDbType.Int,4),
					new SqlParameter("@GroupID", SqlDbType.Int,4),
					new SqlParameter("@ContentDesc", SqlDbType.NText,0),
					new SqlParameter("@DTime", SqlDbType.DateTime,12)};
            parameters[0].Value = model.CID;
            parameters[1].Value = model.ClassID;
            parameters[2].Value = model.GroupID;
            parameters[3].Value = model.ContentDesc;
            parameters[4].Value = model.DTime;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.ContractorDailyMangement model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ContractorDailyMangement set ");
            strSql.Append(" CID=@CID,");
            strSql.Append(" ContentDesc=@ContentDesc");
            strSql.Append(" where CDID=@CDID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CID", SqlDbType.Int,4),
					new SqlParameter("@ContentDesc", SqlDbType.NText,0),
					new SqlParameter("@CDID", SqlDbType.Int,4)};
            parameters[0].Value = model.CID;
            parameters[1].Value = model.ContentDesc;
            parameters[2].Value = model.CDID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ContractorDailyMangement ");
            strSql.Append(" where CDID=@CDID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CDID", SqlDbType.Int,4)};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ContractorDailyMangement ");
            strSql.Append(" where CDID in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContractorDailyMangement GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 CDID,CID,ClassID,GroupID,ContentDesc,DTime from ContractorDailyMangement ");
            strSql.Append(" where CDID=@CDID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CDID", SqlDbType.Int,4)};
            parameters[0].Value = id;

            Catering_Model.ContractorDailyMangement model = new Catering_Model.ContractorDailyMangement();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CDID"] != null && ds.Tables[0].Rows[0]["CDID"].ToString() != "")
                {
                    model.CDID = int.Parse(ds.Tables[0].Rows[0]["CDID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CID"] != null && ds.Tables[0].Rows[0]["CID"].ToString() != "")
                {
                    model.CID = int.Parse(ds.Tables[0].Rows[0]["CID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ClassID"] != null && ds.Tables[0].Rows[0]["ClassID"].ToString() != "")
                {
                    model.ClassID = int.Parse(ds.Tables[0].Rows[0]["ClassID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GroupID"] != null && ds.Tables[0].Rows[0]["GroupID"].ToString() != "")
                {
                    model.GroupID = int.Parse(ds.Tables[0].Rows[0]["GroupID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ContentDesc"] != null && ds.Tables[0].Rows[0]["ContentDesc"].ToString() != "")
                {
                    model.ContentDesc = ds.Tables[0].Rows[0]["ContentDesc"].ToString();
                }
                if (ds.Tables[0].Rows[0]["DTime"] != null && ds.Tables[0].Rows[0]["DTime"].ToString() != "")
                {
                    model.DTime = DateTime.Parse(ds.Tables[0].Rows[0]["DTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CDID,CID,ClassID,GroupID,ContentDesc,DTime ");
            strSql.Append(" FROM ContractorDailyMangement ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" CDID,CID,ClassID,GroupID,ContentDesc,DTime ");
            strSql.Append(" FROM ContractorDailyMangement ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        public int GetCount(string strWhere)
        {
            string sql = "Select Count(*) From ContractorDailyMangement " + strWhere;
            Object obj = DbHelperSQL.GetSingle(sql);
            int sum = 0;
            if (obj != null) Int32.TryParse(obj.ToString(), out sum);
            return sum;
        }

        public Catering_Model.ContractorDailyMangement GetModel(string strWhere)
        {
            string sql = "Select * From ContractorDailyMangement " + strWhere;
            Catering_Model.ContractorDailyMangement model = new Catering_Model.ContractorDailyMangement();
            DataSet ds = DbHelperSQL.Query(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CDID"] != null && ds.Tables[0].Rows[0]["CDID"].ToString() != "")
                {
                    model.CDID = int.Parse(ds.Tables[0].Rows[0]["CDID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CID"] != null && ds.Tables[0].Rows[0]["CID"].ToString() != "")
                {
                    model.CID = int.Parse(ds.Tables[0].Rows[0]["CID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ClassID"] != null && ds.Tables[0].Rows[0]["ClassID"].ToString() != "")
                {
                    model.ClassID = int.Parse(ds.Tables[0].Rows[0]["ClassID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GroupID"] != null && ds.Tables[0].Rows[0]["GroupID"].ToString() != "")
                {
                    model.GroupID = int.Parse(ds.Tables[0].Rows[0]["GroupID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ContentDesc"] != null && ds.Tables[0].Rows[0]["ContentDesc"].ToString() != "")
                {
                    model.ContentDesc = ds.Tables[0].Rows[0]["ContentDesc"].ToString();
                }
                if (ds.Tables[0].Rows[0]["DTime"] != null && ds.Tables[0].Rows[0]["DTime"].ToString() != "")
                {
                    model.DTime = DateTime.Parse(ds.Tables[0].Rows[0]["DTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "ContractorDailyMangement";
            parameters[1].Value = "id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method

        public object DeleteListBywhere(string strWhere)
        {
            string sql = "delete from ContractorDailyMangement " + strWhere;
            int rows = DbHelperSQL.ExecuteSql(sql);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
